package main

import "fmt"

func main() {
	var g Greeter = Person{"姓名恒生", 10, "this is interface!"} // Person 自动实现 Greeter
	g.Greet()

	// 更多赋值示例
	p1 := Person{"张三", 20, "直接初始化"}
	p2 := Person{
		name: "李四",
		age:  25,
		say:  "字段名初始化",
	}

	s3 := Student{
		name: "王五",
		p:    &p1,
	}
	p111 := Person{"张三", 20, "直接初始化&p2"}
	s3.p = &p111

	s4 := Student{}
	s4.name = "钱七"
	s4.pp = Person{"孙八", 35, "后初始化"}

	fmt.Println("\n更多赋值示例:")
	fmt.Println(p1)
	fmt.Println(p2)
	fmt.Println(s3)
	fmt.Println(s3.p)
	fmt.Println(s4)
}

type Greeter interface {
	Greet()
}

type Person struct {
	name string
	age  int
	say  interface{}
}

type Student struct {
	name string
	p    *Person
	pp   Person
}

func (p Person) Greet() {
	fmt.Println("Hello!" + p.name)
	//p.say = p.name
	fmt.Println(p.say)
}
